package com.love.marriage.rechargePackageInfo.service.impl;

import com.love.marriage.rechargePackageInfo.entity.RechargePackageInfo;
import com.love.marriage.rechargePackageInfo.vo.RechargePackageInfoVo;
import com.love.marriage.rechargePackageInfo.mapper.RechargePackageInfoMapper;
import com.love.marriage.rechargePackageInfo.service.RechargePackageInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import com.love.marriage.utils.StringUtils;

/**
 * <p>
 * description:  充值套餐配置表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-10-16 22:50:45
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class RechargePackageInfoServiceImp extends ServiceImpl<RechargePackageInfoMapper, RechargePackageInfo> implements RechargePackageInfoService {

    private final RechargePackageInfoMapper rechargePackageInfoMapper;

    @Override
    public Page<RechargePackageInfoVo> getPage(Long pageNum, Long pageSize, RechargePackageInfoVo rechargePackageInfoVo) {
        Page<RechargePackageInfoVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return rechargePackageInfoMapper.getPage(page, rechargePackageInfoVo);
    }

    @Override
    public List<RechargePackageInfoVo> getList(RechargePackageInfoVo rechargePackageInfoVo) {
        return rechargePackageInfoMapper.getList(rechargePackageInfoVo);
    }

    @Override
    public RechargePackageInfoVo queryRechargePackageInfo(Long id) {
        return rechargePackageInfoMapper.queryRechargePackageInfo(id);
    }

    @Override
    public RechargePackageInfoVo addRechargePackageInfo(RechargePackageInfoVo rechargePackageInfoVo) {
        RechargePackageInfo rechargePackageInfo = new RechargePackageInfo();
        BeanUtils.copyProperties(rechargePackageInfoVo, rechargePackageInfo);
        rechargePackageInfoMapper.insert(rechargePackageInfo);
        RechargePackageInfoVo res = new RechargePackageInfoVo();
        BeanUtils.copyProperties(rechargePackageInfo, res);
        return res;
    }

    @Override
    public RechargePackageInfoVo updateRechargePackageInfo(RechargePackageInfoVo rechargePackageInfoVo) {
        RechargePackageInfo rechargePackageInfo = new RechargePackageInfo();
        BeanUtils.copyProperties(rechargePackageInfoVo, rechargePackageInfo);
        rechargePackageInfoMapper.updateById(rechargePackageInfo);
        return rechargePackageInfoVo;
    }

    @Override
    public Boolean deleteRechargePackageInfo(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        rechargePackageInfoMapper.deleteBatchIds(idArr);
        return true;
    }
}
